//@author wtfumlomglol
package amm.Graphic;

import java.io.*;
import java.util.*;

//specialis mezoket leiro osztaly
public class NotRoad extends Field {
    //mezo tipusa
    private Place place;
    //egyetlen szomszedja van
    private Neighbour neighbour= new Neighbour(null);

    public void setNeighbour(Field f, Compass c, Direction d)
    {
        neighbour= new Neighbour(f);
        neighbour.setCompass(c);
        neighbour.setDirection(d);
    }

    @Override
    public Place getPlace() {
        return place;
    }

    //mivel egy szomszedja van, a parameterektol fuggetlenul
    //ugyanazt ertesiti
    @Override
    public void leave(boolean forward, Compass c) {
        Field next;
        
        //ha civil akar atmenni
        if (c==null)
        {
            next = neighbour.getNextRoute(occupiedBy);
        }
        //ha bankrablo akar atmenni
        else
        {
            next = neighbour.getNextRouteC(occupiedBy);
        }

        //ha a kovetkezo mezo elerheto
        if (next != null) {
            //elmenti a rajta allo auto referenciajat, hogy a clear()
            //utan is riportalhassa a moveTo() visszatereset
            Vehicle veh = occupiedBy;
            //szol a jarmunek, hogy mar atmehet
            occupiedBy.moveTo(next);
        }
        //ha nem elerheto
        else
        {
            //szol a jarmunek, hogy maradjon
            occupiedBy.moveTo(this);
        }
    }

    public void setPlace(Place p)
    {
        place=p;
        switch (place)
        {
            case BANK: name="Bank"; break;
            case HIDEOUT: name="Hideout"; break;
            case POLICEDEPT: name="Police Station"; break;
            default: name="";
        }
    }

    public String getName()
    {
        return name;
    }
}
